 /*
 * @description: 吃货节商品审核
 * @Author: along
 * @Date: 2020-11-30
 * @Last Modified by: along
 * @Last Modified time: 2020-11-30
 */
<template>
    <div class="container shopElevenActive">
        <!-- header -->
        <div class="header-nav">
            <div class="header-left">
                <div class="header-new-box">
                    <p class="header-new-box-title">商品名称/编号:</p>
                    <el-input
                        v-model="formData.goods_title"
                        placeholder="请输入商品名称和编号"
                        size="small"
                        clearable
                        suffix-icon="el-icon-search"
                        @change="getTableData(1)"
                        @keyup.native.enter="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">审核状态:</p>
                    <el-select
                        v-model="formData.status"
                        clearable
                        filterable
                        placeholder="请选择"
                        size="small"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in statusList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">商家名称:</p>
                    <el-select
                        v-model="formData.hire_no"
                        filterable
                        remote
                        clearable
                        size="small"
                        reserve-keyword
                        placeholder="请输入选择名称"
                        :remote-method="remoteMethod"
                        :loading="loading"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in suggestList"
                            :key="item.shop_no"
                            :label="item.shop_title"
                            :value="item.shop_no"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="$refs.goodsSelect.show(2, requestUrl, typeList)"
                    >
                        添加商品
                    </el-button>
                    <el-button
                        type="primary"
                        size="small"
                        @click="goodsImportDialog = true"
                    >
                        导入商品
                    </el-button>
                    <el-button
                        type="primary"
                        size="small"
                        @click="handleExport"
                    >
                        导出
                    </el-button>
                </div>
            </div>
        </div>
        <!-- /header -->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            border
            ref="shopElevenActive"
            @select="fnSelect"
            @select-all="fnSelectAllTop"
            @selection-change="handleSelectionChange"
        >
            <el-table-column
                type="selection"
                width="40"
                fixed="left"
            />
            <el-table-column
                type="index"
                width="80"
                label="序号"
                align="center"
            />
            <el-table-column
                prop="goods_cover"
                label="商品信息"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="170"
            >
                <template slot-scope="scope">
                    <div class="shopInfo">
                        <img
                            :src="scope.row.goods_cover"
                            @click="fnShowPreview(scope.row.goods_cover)"
                        >
                        <div class="wrap">
                            <p class="wrap-title">{{ scope.row.goods_title }}</p>
                            <p class="wrap-no">{{ scope.row.goods_number }}</p>
                        </div>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="goods_no"
                label="商品编号"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="150"
            />
            <el-table-column
                prop="shop_title"
                label="商家名称"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="150"
            />
            <el-table-column
                prop="goods_price"
                label="商品单价"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="goods_activity_price"
                label="吃货节活动价"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="150"
            />
            <el-table-column
                prop="goods_freight"
                label="计费方式"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.freight_type == 'weight' ? '按重量计费' : (scope.row.freight_type == 'num' ? '按件计费' : (scope.row.freight_type == 'fix' ? '固定邮费' : '--')) }}
                </template>
            </el-table-column>
            <el-table-column
                prop="goods_freight"
                label="商品运费"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                label="规格信息"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <p
                        :style="{color: '#409EFF', cursor: 'pointer'}"
                        @click="checkproduct(scope.row)"
                    >
                        查看
                    </p>
                </template>
            </el-table-column>
            <el-table-column
                prop="product_stock"
                label="库存"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="reduction_info"
                label="优惠力度"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <div class="cursor-font">
                        <el-popover
                            placement="left"
                            :width="scope.row.reduction_info.list.length == 0 ? 120 :'auto'"
                        >
                            <div
                                v-if="scope.row.reduction_info.list.length > 0"
                                :style="{width: '100%', textAlign: 'center', display: 'flex', flexDirection: 'column'}"
                            >
                                <div :style="{height: '28px', display: scope.row.reduction_info.list.length > 1 ? 'flex' : '', alignItems: 'center'}">
                                    <div
                                        v-for="(item, index) in scope.row.reduction_info.list"
                                        :key="index"
                                    >
                                        <div
                                            v-if="index <= 2"
                                            class="reduction_price"
                                            :style="{color: scope.row.reduction_info.reduction_type == 2 ? '#FF3030' : '#FDA623', borderColor: scope.row.reduction_info.reduction_type == 2 ? '#FF3030' : '#FDA623', margin: index == 1 ? (scope.row.reduction_info.list.length == 2 ? '0 0 0 12px' : '12px') : '0'}"
                                        >
                                            满{{ item.require_num }}{{ scope.row.reduction_info.reduction_type == 2 ? '' : '件' }}减{{ item.reduction_price }}
                                        </div>
                                    </div>
                                </div>
                                <div
                                    :style="{height: '28px', display: 'flex', alignItems: 'center', marginTop: '18px'}"
                                    v-if="scope.row.reduction_info.list.length > 3"
                                >
                                    <div
                                        v-for="(item, index) in scope.row.reduction_info.list"
                                        :key="index"
                                    >
                                        <div
                                            v-if="index > 2"
                                            class="reduction_price"
                                            :style="{color: scope.row.reduction_info.reduction_type == 2 ? '#FF3030' : '#FDA623', borderColor: scope.row.reduction_info.reduction_type == 2 ? '#FF3030' : '#FDA623', margin: index == 4 ? (scope.row.reduction_info.list.length == 5 ? '0 0 0 12px' : '12px') : '0'}"
                                        >
                                            满{{ item.require_num }}{{ scope.row.reduction_info.reduction_type == 2 ? '' : '件' }}减{{ item.reduction_price }}
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div
                                v-else
                                :style="{width: '100%', textAlign: 'center'}"
                            >
                                暂无数据
                            </div>
                            <el-button
                                slot="reference"
                                type="text"
                            >
                                查看
                            </el-button>
                        </el-popover>
                    </div>
                </template>
            </el-table-column>
            <el-table-column
                prop="goods_cate_name_list"
                label="商品组"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    {{ scope.row.goods_cate_name_list.length > 0 ? scope.row.goods_cate_name_list.join() : '--' }}
                </template>
            </el-table-column>
            <el-table-column
                prop="buy_limit_count"
                label="限购数量"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            />
            <el-table-column
                prop="verify"
                label="审核状态"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
            >
                <template slot-scope="scope">
                    <p v-if="scope.row.verify == 0">未提交</p>
                    <p v-if="scope.row.verify == 1">待审核</p>
                    <p v-if="scope.row.verify == 2">审核不通过</p>
                    <p v-if="scope.row.verify == 3">审核通过</p>
                </template>
            </el-table-column>
            <el-table-column
                prop="submit_time"
                label="提交时间"
                show-overflow-tooltip
                :formatter="emptyFormatter"
                align="left"
                :width="150"
            >
                <template slot-scope="scope">
                    {{ scope.row.submit_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                fixed="right"
                :width="200"
            >
                <template slot-scope="scope">
                    <el-button
                        type="text"
                        class="curse-add"
                        @click="agree(scope.row)"
                        :disabled="scope.row.verify == 3 || scope.row.verify == 0"
                    >
                        通过
                    </el-button>
                    <el-button
                        type="text"
                        class="curse-add"
                        @click="refuse(scope.row)"
                        :disabled="scope.row.verify == 2 || scope.row.verify == 0"
                    >
                        拒绝
                    </el-button>
                    <el-button
                        type="text"
                        class="curse-add"
                        @click="editGroup(scope.row)"
                        :disabled="scope.row.verify !== 3"
                    >
                        分配商品组
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- /分页 -->
        <div class="pagination-wrapper clearfix">
            <el-checkbox
                v-model="checkedAll"
                :indeterminate="checkIndeterminate"
                @change="fnChangeChecked"
            >全选</el-checkbox>
            <el-button
                type="text"
                :disabled="multipleSelection.length == 0 ? true : false"
                :style="{marginLeft: '10px'}"
                @click="allSuccess()"
            >通过</el-button>
            <el-button
                type="text"
                :disabled="multipleSelection.length == 0 ? true : false"
                @click="allError()"
            >拒绝</el-button>
            <el-button
                type="text"
                :disabled="multipleSelection.length == 0 ? true : false"
                @click="setGroup()"
            >推荐到商品组</el-button>
            <el-pagination
                background
                layout="total, prev, pager, next"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>

        <!-- 图片预览 -->
        <img-preview ref="preview" />

        <!-- 拒绝弹窗 -->
        <el-dialog
            title="驳回原因"
            :visible.sync="dialogVisibleError"
            width="614px"
            :close-on-click-modal="false"
        >
            <el-input
                v-model="reson"
                type="textarea"
                :autosize="{ minRows: 4, maxRows: 6}"
                placeholder="请输入内容"
                maxlength="100"
                show-word-limit
            />
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    @click="dialogVisibleError = false"
                    size="medium"
                    type="default"
                    :style="{width: '120px', marginRight: '32px'}"
                >
                    取 消
                </el-button>
                <el-button
                    type="primary"
                    size="medium"
                    :style="{width: '120px'}"
                    :disabled="!reson"
                    @click="confirmRefueL()"
                >
                    提 交
                </el-button>
            </span>
        </el-dialog>

        <!-- 商品规格信息 -->
        <el-dialog
            title="商品规格信息"
            :visible.sync="dialogVisibleProduct"
            width="680px"
            :close-on-click-modal="false"
        >
            <el-table
                :data="productList"
                height="100%"
                style="width: 100%;max-height: 450px"
                border
            >
                <el-table-column
                    prop="spec_list"
                    label="规格名称"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        {{ scope.row.spec_list | filterSpec }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="activity_price"
                    label="吃货节活动价"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="product_price"
                    label="单独购买价"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
                <el-table-column
                    prop="goods_commission_rate"
                    label="佣金比例"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        {{ scope.row.goods_commission_rate }}%
                    </template>
                </el-table-column>
                <el-table-column
                    prop="product_commission"
                    label="分佣金额"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                >
                    <template slot-scope="scope">
                        {{ calcCommission(scope.row) }}
                    </template>
                </el-table-column>
                <el-table-column
                    prop="product_stock"
                    label="库存"
                    show-overflow-tooltip
                    :formatter="emptyFormatter"
                    align="center"
                />
            </el-table>
            <span
                slot="footer"
                class="dialog-footer"
            >
                <el-button
                    @click="dialogVisibleProduct = false"
                    size="medium"
                    type="primary"
                >
                    我知道了
                </el-button>
            </span>
        </el-dialog>

        <!-- 设置商品组 -->
        <shop-group
            ref="shopGroup"
            @sendData="getData"
        />
        <!--商品选择弹窗-->
        <goods-select
            ref="goodsSelect"
            @change="handleSelectGoods"
        />
        <!-- 导入商品 -->
        <goods-import
            @change="handleSelectGoods($event.list)"
            :visible.sync="goodsImportDialog"
            :request-url="requestUrl"
        />
    </div>
</template>

<script>
import imgPreview from '@/components/common/img-preview';
import shopGroup from '@/components/student/shop-group';
import GoodsSelect from '@/components/goods/goods-select';
import GoodsImport from "@/components/goods/goods-import";
import { back } from '@/mixin/back';

export default {
    mixins: [back],
    components: {
        imgPreview,
        shopGroup,
        GoodsSelect,
        GoodsImport
    },
    data () {
        return {
            ID: '',//商品唯一编号
            reson: '',//拒绝理由
            productList: [],
            dialogVisibleProduct: false,
            dialogVisibleError: false,
            loading: false,
            checkIndeterminate: false,
            multipleSelection: [],
            checkedAll: false,
            formData: {
                goods_title: '',
                status: 99,
                hire_no: ''
            },
            suggestList: [],
            statusList: [{value: 99,label: '全部'},{value: 0,label: '未提交'},{value: 1,label: '待审核'},{value: 3,label: '审核已通过'},{value: 2,label: '审核未通过'}],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            tableData: [],
            authResult: {},
            // 商品弹窗类型
            typeList: [
                {label: '自营', value: 1},
                {label: '折扣', value: 5},
                {label: '秒杀', value: 3}
            ],
            requestUrl: '/student/shop_goods%5Cget_list_for_select',
            goodsImportDialog: false,
            goods_commission_rate: '',
        };
    },
    filters: {
        filterSpec (val) {
            let str = '';

            val.forEach((el, n) => {
                str += el.spec_name + ':' + el.spec_value + (n == val.length - 1 ? '' : ';');
            });

            return str;
        }
    },
    computed: {},
    watch: {
        dialogVisibleError (val) {
            if(!val) {
                this.reson = '';
            }
        }
    },
    mounted () {
        this.$store.commit('SET_HEADER', [{ title: "APP后台"},{title: '商城'},{title: '审核商品'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
        this.getSuggest('');
    },
    methods: {
        /**
         * @description 获取表格数据
         */
        getTableData (page) {
            this.$post('/student/activity%5Ca20210517_get_list', {
                page_id: page || this.page.now_page,
                verify: this.formData.status,
                shop_no: this.formData.hire_no,
                goods_keyword: this.formData.goods_title
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        /**
         * @description 查看商品规格信息
         */
        checkproduct (row) {
            let activity_price = no => {
                let list = row.activity_product_info;

                for(let key=0; key<list.length; key++) {
                    if(list[key]['product_no'] === no) {
                        return list[key]['activity_price'];
                    }
                }
            };

            this.getProductList(row).then(resp => {
                resp.forEach(el => {
                    el.activity_price = activity_price(el.product_no);
                    el.goods_commission_rate = this.goods_commission_rate;
                });
                this.productList = resp;
                this.dialogVisibleProduct = !this.dialogVisibleProduct;
            });
        },

        /**
         * @description 获取商品规格信息
         */
        getProductList (row) {
            return new Promise((resolve,reject) => {
                this.$post('/student/shop_goods%5Cget_product', {
                    goods_no: row.goods_no
                }, resp=> {
                    if (resp.code == 1) {
                        this.goods_commission_rate = resp.data.goods_commission_rate;
                        resolve(resp.data.goods_product_list);

                    } else if (resp.code == 0) {
                        return;
                    }
                });
            });
        },

        /**
         * @description 获取商家列表
         */
        getSuggest (keyword) {
            this.$post('/student/shop%5Csuggest', {
                keyword: keyword
            }, resp => {
                if (resp.code == 1) {
                    this.suggestList = resp.data.list;
                }
            });
        },

        /**
         * @description 搜索商家名称
         */
        remoteMethod (query) {
            if (query !== '') {
                this.loading = true;
                setTimeout(() => {
                    this.loading = false;
                    this.getSuggest(query);
                }, 200);
            }
        },

        /**
         * @description 批量商品组
         */
        setGroup () {
            if(true) {
                this.$refs.shopGroup.show();
                this.$refs.shopGroup.getType('add');
            }
        },

        /**
         * 获取推荐到商品组数据
         */
        getData (resp) {
            if(resp.type == 'add' && !resp.isNext) {
                let goods_no = this.multipleSelection.reduce((cur,next) => {
                    cur.push(next.goods_no);
                    return cur;
                },[]);

                this.$post('/student/shop_goods%5Cjoin_cate', {
                    goods_nos: goods_no.join(),
                    data_nos: resp.data.join()
                }, resp => {
                    if (resp.code == 1) {
                        this.$refs.shopGroup.hide();
                        this.getTableData();
                        this.$message({
                            type: 'success',
                            message: '操作成功'
                        });
                    } else {
                        this.$message({
                            type: 'warning',
                            message: resp.msg
                        });
                    }
                });
            }

            if(resp.type == 'add' && resp.isNext) {
                this.$post('/student/shop_goods%5Cjoin_cate', {
                    goods_nos: this.nextId,
                    data_nos: resp.data.join()
                }, resp => {
                    if (resp.code == 1) {
                        this.$refs.shopGroup.hide();
                        this.getTableData();
                        this.$message({
                            type: 'success',
                            message: '操作成功'
                        });
                    } else {
                        this.$message({
                            type: 'warning',
                            message: resp.msg
                        });
                    }
                });
            }

            if(resp.type == 'edit') {
                this.$post('/student/shop_goods%5Cset_cate', {
                    goods_nos: resp.goods_no,
                    data_nos: resp.data.join()
                }, resp => {
                    if (resp.code == 1) {
                        this.$refs.shopGroup.hide();
                        this.getTableData();
                        this.$message({
                            type: 'success',
                            message: '编辑成功'
                        });
                    } else {
                        this.$message({
                            type: 'warning',
                            message: resp.msg
                        });
                    }
                });
            }
        },

        /**
         * @description 编辑商品组
         */
        editGroup (row) {
            this.$post('/student/shop_goods%5Ccurrent_cate', {
                goods_no: row.goods_no
            }, resp => {
                if (resp.code == 1) {
                    if(Object.prototype.toString.call(resp.data) !== '[object Null]' && resp.data.list.length > 0) {
                        this.$refs.shopGroup.getType('edit', {
                            data: resp.data,
                            goods_no: row.goods_no
                        });
                        this.$refs.shopGroup.show();
                    } else {
                        this.nextId = row.goods_no;
                        this.$refs.shopGroup.show();
                        this.$refs.shopGroup.getType('add');
                        this.$refs.shopGroup.getNext(true);
                        return false;
                    }
                } else {
                    this.$message({
                        type: 'warning',
                        message: resp.msg
                    });
                }
            });
        },

        /**
         * @description 通过
         */
        agree (row) {
            if(!this.authResult.auth_verfy) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            this.$confirm('是否要通过此商品?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$post('/student/activity%5Ca20210517_verify',{
                    hire_no: row.hire_no,
                    goods_no: row.goods_no,
                    verify: 3
                },resp=>{
                    if (resp.code == 1) {
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '操作成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '提示',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            });
        },

        /**
         * @description 批量通过
         */
        allSuccess () {
            if(!this.authResult.auth_verfy) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            let no = this.multipleSelection.reduce((cur,next) => {
                cur.push({hire_no: next.hire_no, goods_no: next.goods_no});
                return cur;
            },[]);

            this.$confirm('是否要批量通过所选择商品?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                no.forEach(el => {
                    this.$post('/student/activity%5Ca20210517_verify',{
                        hire_no: el.hire_no,
                        goods_no: el.goods_no,
                        verify: 3
                    },resp=>{
                        if (resp.code == 1) {
                            //
                        }
                    });
                });

                setTimeout(() => {
                    this.getTableData();
                    this.$notify({
                        title: '提示',
                        message: '操作成功',
                        type: 'success',
                        duration: 2000
                    });
                },500);
            });
        },

        /**
         * @description 拒绝
         */
        refuse (row) {
            if(!this.authResult.auth_verfy) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            this.type = '1';
            this.ID = row.hire_no;
            this.goods_no = row.goods_no;
            this.dialogVisibleError = !this.dialogVisibleError;
        },

        /**
         * @description 确定拒绝
         */
        confirmRefueL () {
            if(this.type == '1') {
                this.$post('/student/activity%5Ca20210517_verify',{
                    hire_no: this.ID,
                    goods_no: this.goods_no,
                    verify: 2,
                    verify_fail_reason: this.reson
                },resp=>{
                    if (resp.code == 1) {
                        this.dialogVisibleError = !this.dialogVisibleError;
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '操作成功',
                            type: 'success',
                            duration: 2000
                        });
                    } else if (resp.code == 0) {
                        this.$notify({
                            title: '提示',
                            message: resp.msg,
                            type: 'warning',
                            duration: 2000
                        });
                    }
                });
            }

            if(this.type == '2') {
                let no = this.multipleSelection.reduce((cur,next) => {
                    cur.push({hire_no: next.hire_no, goods_no: next.goods_no});
                    return cur;
                },[]);


                no.forEach(el => {
                    this.$post('/student/activity%5Ca20210517_verify',{
                        hire_no: el.hire_no,
                        goods_no: el.goods_no,
                        verify: 2,
                        verify_fail_reason: this.reson
                    },resp=>{
                        if (resp.code == 1) {
                            //
                        }
                    });

                    setTimeout(() => {
                        this.dialogVisibleError = !this.dialogVisibleError;
                        this.getTableData();
                        this.$notify({
                            title: '提示',
                            message: '操作成功',
                            type: 'success',
                            duration: 2000
                        });
                    },500);
                });
            }
        },

        /**
         * @description 批量拒绝
         */
        allError () {
            if(!this.authResult.auth_verfy) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }

            this.type = '2';
            this.dialogVisibleError = !this.dialogVisibleError;
        },

        /**
         * @description 全选逻辑操作
         */
        fnSelect(selection) {
            if(selection.length == this.tableData.length) {
                this.checkedAll = true;
            }else{
                this.checkedAll = false;
            }
            if(selection.length > 0 && selection.length < this.tableData.length) {
                this.checkIndeterminate = true;
            }else{
                this.checkIndeterminate = false;
            }
        },
        fnSelectAllTop(selection) {
            if(selection.length > 0) {
                this.checkedAll = true;
            }else{
                this.checkedAll = false;
            }
            if(selection.length > 0 && selection.length < this.tableData.length) {
                this.checkIndeterminate = true;
            }else{
                this.checkIndeterminate = false;
            }
        },
        fnChangeChecked() {
            if(this.checkedAll){
                this.toggleSelection(1);
            }else{
                this.toggleSelection();
            }
        },
        toggleSelection(rows) {
            if (rows) {
                this.$refs.shopElevenActive.toggleAllSelection();
            } else {
                this.$refs.shopElevenActive.clearSelection();
            }
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },

        /**
         * @description 查看图片
         * @param   {String}    images    单图预览
         * @param   {Array}     images     多图预览
         */
        fnShowPreview(images) {
            if(images && Object.prototype.toString.call(images) == '[object String]') {
                this.$refs.preview.show([
                    images
                ]);
            } else if (images && Object.prototype.toString.call(images) == '[object Array]') {
                this.$refs.preview.show(images);
            } else {
                this.$notify({
                    title: '提示',
                    message: '图片类型错误',
                    type: 'warning',
                    duration: 2000
                });
            }
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if(val === 0) return val;
            if (!val) return '--';
            return val;
        },

        /**
         * 导出数据
         */
        handleExport() {
            let params = {
                verify: this.formData.status,
                shop_no: this.formData.hire_no,
                goods_keyword: this.formData.goods_title
            };

            let base = this.$baseUrl;
            let ticket = localStorage.getItem('sessionTicket');
            let url = `${base}/student/activity%5Ca20210517_export_list?verify=${params.verify}&shop_no=${params.shop_no}&goods_keyword=${params.goods_keyword}&__ticket=${ticket}`;

            window.open(url);
        },

        /**
         * 获取批量选择的商品
         * @param val
         */
        handleSelectGoods(val) {
            if(val.length === 0) {
                this.$message.warning('批量设置商品为空');
                return;
            }
            this.$router.push({
                path: '/student/active-goods-add',
                query: {
                    goodsList: JSON.stringify(val)
                }
            });
        },

        /**
         * 计算分佣金额
         * @param row
         */
        calcCommission(row) {
            if(row.activity_price) {
                // console.log(Number(row.activity_price) * (Number(row.goods_commission_rate) / 100));
                return (Number(row.activity_price) * (Number(row.goods_commission_rate) / 100)).toFixed(2);
            } else {
                return '--';
            }
        }
    }
};
</script>

<style lang="less" scoped>
    .container {
        background-color: #fff;
        padding: 10px 15px 5px 15px;
        display: flex;
        flex-direction: column;
        position: relative;
        width: 100%;
        .header-nav {
            position: relative;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
            .header-left, .header-right {
                display: flex;
                align-items: center;
                flex-wrap: wrap;
            }
            .header-new-box {
                display: flex;
                margin-right: 15px;
                align-items: center;
                color: #606266;
                margin-bottom: 10px;
                white-space: nowrap;
                &-title {
                    margin-right: 2px;
                    white-space: nowrap;
                }
            }
        }
        /* 表单 */
        .scope-price {
            width: 50px;
            height: 50px;
        }
        /* 字体高亮 */
        .cursor-font {
            color: rgb(64, 158, 255);
            cursor: pointer;
        }
        /* 分页 */
        .pagination-wrapper {
            padding-top: 10px;
            padding-bottom: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /* 排序 */
    .sort-wrap {
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        .sort-spliter {
            width: 1px;
            height: 12px;
            background: rgba(235, 235, 235, 1);
            margin: 0 10px;
            }
            .btn-sort {
            font-size: 14px;
            line-height: 1;
            color: #ccc;
            &:hover {
                color: #20a0ff;
            }
        }
    }
    .el-button-left {
        margin-left: 40px;
    }
    .el-button-right {
        margin-right: 10px;
    }
    .dialog-footer {
        display: flex;
        justify-content: center;
    }
    .shopInfo {
        display: flex;
        height: 50px;
        &>img {
            width: 50px;
            height: 50px;
            margin-right: 10px;
            cursor: pointer;
        }
        .wrap {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            &-title {
                color: #333;
                font-size: 14px;
                max-width: 300px;
                overflow : hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp: 2;
                -webkit-box-orient: vertical;
                line-height: 35px;
            }
            &-no {
                color: #333;
                font-size: 14px;
            }
        }
    }
    .reduction_price {
        color: #FF3030;
        font-size: 14px;
        box-sizing: border-box;
        border: 1px #FF3030 solid;
        border-radius: 4px;
        padding: 7px 5px;
    }
</style>
<style lang="less">
    .shopElevenActive{
        .el-table__body-wrapper .el-table__body .el-table__row td {
            border-right: none;
        }
        .el-table__header-wrapper .el-table__header .has-gutter tr th {
            border-right: none;
        }
        .el-table .el-table_1_column_6  .cell {
            position: relative;
        }
        .el-range-editor--small .el-range-separator{
            padding: 0 1px !important;
        }
        .el-dialog__header {
            padding-top: 10px;
            box-shadow:0px 1px 0px 0px rgba(233,233,233,1);
            display: flex;
            align-items: center;
            background: #FAFAFA;
            border-radius: 4px 4px 0 0;
            .el-dialog__title {
                font-weight: 500;
                color: #333;
                font-size: 14px;
            }
            .el-icon-close:before {
                color: rgb(194,194,194);
                font-size: 17px;
                font-weight: bold;
            }
            .el-dialog__headerbtn {
                top: 14px;
            }
        }
        .el-textarea__inner {
            resize: none;
        }
    }
</style>
